from azure.iot.device import IoTHubDeviceClient, Message


# 连接信息
connection_str = "HostName=E2R4S05IOTSPN001.azure-devices.cn;DeviceId=861198060661337;SharedAccessKey=hvHXRImlfSkhSkKWoZUghob89gRxiQ8sUSbrcPJZZc4="
consumer_group = "cto_debug"
device_id = "861198060661337"  # 替换为实际的设备 ID
def message_handler(message):
    if message.input_name == "events":
        print(f"Received event from device: {message.data.decode()}")

client = IoTHubDeviceClient.create_from_connection_string(connection_str)
client.connect()
client.on_message_received = message_handler

# 订阅事件
client.subscribe_to_events(consumer_group)

while True:
    pass

client.disconnect()
